package com.portal.cwegportal.service;

import com.appcenter.jz.app.CurrentUser;
import com.portal.cwegportal.input.userimpmaccount.CreateUserImPmAccountInput;
import com.portal.cwegportal.input.userimpmaccount.GetUserImPmAccountInput;
import com.portal.cwegportal.mapper.UserImPmAccountMapper;
import com.portal.cwegportal.model.UserImPmAccount;
import com.portal.cwegportal.output.userimpmaccount.CreateUserImPmAccountOutput;
import com.portal.cwegportal.output.userimpmaccount.GetUserImPmAccountOutput;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Service
public class UserImPmAccountService {
    @Autowired
    UserImPmAccountMapper userImPmAccountMapper;
    /**
     *  创建人:王增立
     *  备注: 新增修改当前人的密码
     *  时间: 2019/4/26 15:09
     *  参数:
     */
     @Transactional
    public CreateUserImPmAccountOutput createUserImPmAccount (CreateUserImPmAccountInput input) throws Exception{
        CreateUserImPmAccountOutput output=new CreateUserImPmAccountOutput();

        UserImPmAccount uip=new UserImPmAccount();
        uip.setAccountNumber(input.getAccountName());
        uip.setPassword(input.getAccountPassWord());
        uip.setTypeKey(input.getAccountTypeKey());
       uip.setCreatorCode(CurrentUser.getUserCode());
        uip.setCreatorId(CurrentUser.getUserId());
        uip.setCreatorName(CurrentUser.getUserName());
        uip.setDeleted(false);
        uip.setGmtCreate(new Date());
        userImPmAccountMapper.deleteByUserCode(uip.getCreatorCode(),uip.getTypeKey());
        userImPmAccountMapper.insertSelective(uip);
        return  output;
    }
    /**
     *  创建人:王增立
     *  备注: 获取当前人的账号密码
     *  时间: 2019/4/26 15:09
     *  参数:
     */
    @Transactional
    public GetUserImPmAccountOutput getImPmAccountByTypeKey(GetUserImPmAccountInput input) throws Exception{
        GetUserImPmAccountOutput output = new GetUserImPmAccountOutput();
        output.setUserPassWordExistence(false);
        UserImPmAccount Uipa= userImPmAccountMapper.selectByUserCode(CurrentUser.getUserCode(),input.getAccountTypeKey());
        if(Uipa!=null){
            output.setItem(Uipa);
            output.setUserPassWordExistence(true);
        }


        return output;
    }

}
